package com.factory;

import com.pojo.Person;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

public class beanFactory {
    static Map<String, Person> map = new HashMap<>();


    static {
        Properties properties = new Properties();
        InputStream is = beanFactory.class.getClassLoader().getResourceAsStream("Person.properties");

        try {
            properties.load(is);
            Set<Object> keys = properties.keySet();
            for (Object key:keys) {
                String personName = properties.getProperty(String.valueOf(key));
                Person o = (Person) Class.forName(personName).newInstance();
                map.put(""+key,o);
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public Person getBean( String personName){
        Person person = map.get(personName);
        return person;
    }
}
